﻿Imports System.Data.OleDb
Public Class Add_an_Experience
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_submit.Click

        Dim myGuid As New System.Guid
        myGuid = Guid.NewGuid()
        Dim newFileName As String
        newFileName = myGuid.ToString() & ".jpg"

        If f_photo.HasFile() = True Then

            f_photo.SaveAs(Request.MapPath("Pictures") & "/" & newFileName)

        End If


        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("TravellingAloneConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into experiences(the_author, the_title, the_location, the_time, the_description, the_photo) Values (@f1,@f2,@f3,@f4,@f5,@f6)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f2", tb_title.Text)
        cmd.Parameters.AddWithValue("@f3", tb_location.Text)
        cmd.Parameters.AddWithValue("@f4", tb_time.Text)
        cmd.Parameters.AddWithValue("@f5", tb_description.Text)
        cmd.Parameters.AddWithValue("@f6", "Pictures/" & newFileName)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("Default.aspx")

    End Sub
End Class